﻿Imports System.Data.SqlClient

Public Class clsOrdenDetalleServicios
    Private mintIdOrden As Integer
    Private mintIdMantenimiento As Integer
    Private mintIdServicio As Integer
    Private mstrNombreServicio As String
    Private mdblKilometraje As Double
    Private mintTipo As Integer
    Private mintRealizado As Integer
    Private mintDiasDiferencia As Integer
    Public Property IdOrden() As Integer
        Get
            Return mintIdOrden
        End Get
        Set(ByVal value As Integer)
            mintIdOrden = value
        End Set
    End Property
    Public Property IdMantenimiento() As Integer
        Get
            Return mintIdMantenimiento
        End Get
        Set(ByVal value As Integer)
            mintIdMantenimiento = value
        End Set
    End Property
    Public Property IdServicio() As Integer
        Get
            Return mintIdServicio
        End Get
        Set(ByVal value As Integer)
            mintIdServicio = value
        End Set
    End Property
    Public Property NombreServicio() As String
        Get
            Return mstrNombreServicio
        End Get
        Set(value As String)
            mstrNombreServicio = value
        End Set
    End Property
    Public Property Kilometraje() As Double
        Get
            Return mdblKilometraje
        End Get
        Set(ByVal value As Double)
            mdblKilometraje = value
        End Set
    End Property
    Public Property Tipo() As Integer
        Get
            Return mintTipo
        End Get
        Set(ByVal value As Integer)
            mintTipo = value
        End Set
    End Property
    Public Property Realizado() As Integer
        Get
            Return mintRealizado
        End Get
        Set(ByVal value As Integer)
            mintRealizado = value
        End Set
    End Property
    Public Property DiasDiferencia() As Integer
        Get
            Return mintDiasDiferencia
        End Get
        Set(ByVal value As Integer)
            mintDiasDiferencia = value
        End Set
    End Property
    Public Sub New()
        mintIdOrden = 0
        mintIdMantenimiento = 0
        mintIdServicio = 0
        mstrNombreServicio = ""
        mdblKilometraje = 0
        mintTipo = 0
        mintRealizado = 0
        mintDiasDiferencia = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into OrdenDetalleServicios (" & _
                            "IdMantenimiento," & _
                            "IdServicio," & _
                            "NombreServicio," & _
                            "Kilometraje," & _
                            "Tipo," & _
                            "Realizado," & _
                            "DiasDiferencia) " & _
                            "VALUES (" & _
                            "@IdMantenimiento," & _
                            "@IdServicio," & _
                            "substring(@NombreServicio,1,200)," & _
                            "@Kilometraje," & _
                            "@Tipo," & _
                            "@Realizado," & _
                            "@DiasDiferencia) "


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdMantenimiento", mintIdMantenimiento)
        Command.Parameters.AddWithValue("IdServicio", mintIdServicio)
        Command.Parameters.AddWithValue("NombreServicio", mstrNombreServicio)
        Command.Parameters.AddWithValue("Kilometraje", mdblKilometraje)
        Command.Parameters.AddWithValue("Tipo", mintTipo)
        Command.Parameters.AddWithValue("Realizado", mintRealizado)
        Command.Parameters.AddWithValue("DiasDiferencia", mintDiasDiferencia)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Orden de servicios ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
